<template>
  <div>
    <div><h1>字典管理</h1></div>
    <div>
      <el-button type="primary" @click="handleAdd">添加</el-button>
    </div>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="dictId" label="字典序号" />
      <el-table-column prop="dictName" label="字典名称" />
      <el-table-column prop="dictValue" label="字典值" />
      <el-table-column prop="dictType" label="字典类型" />
      <el-table-column label="操作">
        <template #default="scope">
          <el-button type="primary" size="small" @click="handleEdit(scope.row)"
            >编辑</el-button
          >
          <el-button type="danger" @click="handleDelete(scope.row)" size="small"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 20px;">
      <el-pagination
        v-model:current-page="pageInfoVo.pageNum"
        v-model:page-size="pageInfoVo.pageSize"
        :page-sizes="[2, 4, 6, 8]"
        :background="true"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { getDictList } from "@/api/api";
//列表数据
const tableData = ref([]);
//分页条数
const total = ref(0);
//查询条件
const pageInfoVo = ref({
  pageNum: 1,
  pageSize: 4,
});
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  pageInfoVo.value.pageSize = val;
  loadDictList();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  pageInfoVo.value.pageNum = val;
  loadDictList();
};
const loadDictList = () => {
  getDictList(pageInfoVo.value).then((res) => {
    tableData.value = res.data.data.records;
    total.value = res.data.data.total;
  });
};
const handleAdd = () => {};
onMounted(() => {
  loadDictList();
});
</script>

<style scoped></style>
